//
//  SliderTableViewCell.m
//  WWAVPlayer
//
//  Created by dllo on 15/10/31.
//  Copyright © 2015年 LZY. All rights reserved.
//

#import "SliderTableViewCell.h"
#import "Blocks.h"
#import "HorizontalCollectionViewCell.h"
#import <UIImageView+WebCache.h>
@interface SliderTableViewCell()<UICollectionViewDataSource,UICollectionViewDelegate>
@property (nonatomic,strong) UICollectionViewFlowLayout *flow;

@end
@implementation SliderTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.flow = [[UICollectionViewFlowLayout alloc] init];
        self.flow.itemSize = CGSizeMake(Screen_Width / 1.5 - 1, 120);
        self.flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        
        self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, 200) collectionViewLayout:self.flow];
        
        self.flow.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
       self.collectionView.showsHorizontalScrollIndicator = NO;
        self.collectionView.backgroundColor = [UIColor whiteColor];
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        self.flow.minimumLineSpacing = 0;
        self.flow.minimumInteritemSpacing = 0;
        [self.contentView addSubview:self.collectionView];
        
        [self.collectionView registerClass:[HorizontalCollectionViewCell class] forCellWithReuseIdentifier:@"bbbb"];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.flow.itemSize = CGSizeMake(Screen_Width / 1.8 - 1, 120);
    self.collectionView.frame = self.contentView.bounds;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.block.contents.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HorizontalCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"bbbb" forIndexPath:indexPath];
   
    [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:[[self.block.contents objectAtIndex:indexPath.item] objectForKey:@"still"]]];
    
    cell.myLabel.text = [[self.block.contents objectAtIndex:indexPath.item] objectForKey:@"name"];
    
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [self.block.contents objectAtIndex:indexPath.item];
    
    [self.delegate passToCollectionWithIdNum:[dic objectForKey:@"mid"]];
    
    
}
@end
